home *** CD-ROM | disk | FTP | other *** search
- Path: qcd.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: char* string problem
- Date: 5 Jan 1996 20:38:44 GMT
- Organization: Los Alamos National Laboratory
- Distribution: world
- Message-ID: <4ck28k$mv7@newshost.lanl.gov>
- References: <4ci7gu$68r@cloner3.netcom.com> <820846052snz@intellic.demon.co.uk>
- NNTP-Posting-Host: qcd.lanl.gov
-
- In article <820846052snz@intellic.demon.co.uk>, Chris Trueman
- <truemanc@intellic.demon.co.uk> writes:
- |> In article <4ci7gu$68r@cloner3.netcom.com>
- |> tstevens@ix.netcom.com "Edward Stevens " writes:
- <snip>
- |> >char* Aprefix = " -A";
- <snip>
- |> >the_args[0] = strcat(Aprefix,the_args[0]);
- |>
- |> Your problem is that the_args[0] is being set to the address of
- |> Aprefix which points to three (3) blocks of memory. By executing the
- |> strcat you are overwriting memory you have not already allocated.
-
- More importantly, string literals are _constants_. Trying to modify them in
- _any_ way leads to undefined behaviour (when not a diagnosable error, that
- is). strcat tries to modify the first '\0' which forms part of the string: in
- this case the fourth character of the string literal. (Yes, sizeof " -A" is 4
- not 3).
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-